import {handleActions} from 'redux-actions';
import * as types from '../../utils/type/CommonTypes';

const defaultStatus = {
    datas: [],
    articleDatas:[]
};

export default handleActions({
    [types.FETCH_SORT_DONE]: (state, action) => {
        return {
            ...state,
            datas: action.payload
        }
    },
    [types.FETCH_SORT_ARTICLE_DOING]:(state, action) => {
        return {
            ...state
        }
    },
    [types.FETCH_SORT_ARTICLE_DONE]:(state, action) => {
        const data = action.payload;
        let datas = state.articleDatas;
        if (data.curPage === 1) {
            datas = data.datas;
        } else {
            datas = [...datas, ...data.datas]
        }
        //let isEnd = data.curPage > data.pageCount;
        return {
            ...state,
            articleDatas: datas
        }
    }
}, defaultStatus);